package temp

import (
	"github.com/PuerkitoBio/goquery"
	"regexp"
	"strings"
)

type Cart struct {

}

func (c Cart) CheckAvailable(document *goquery.Document) map[string]string {
	content := document.Find(".a-alert-content p").Text()

	if strings.Contains(content, "per customer") {
		return map[string]string{
			"status": "error",
			"reason": "limit",
		}
	}

	matcher, _ := regexp.Compile(`than the ([\d]+) available`)
	results := matcher.FindStringSubmatch(content)
	if len(results) > 0 {
		return map[string]string{
			"status": "success",
			"qty": results[1],
		}
	}


	return map[string]string{
		"status": "error",
		"reason": "unknown",
	}
}
